#include "stdafx.h"
#include "BuffManager.h"

BuffManager::BuffManager()
{
}
BuffManager::~BuffManager()
{

}

void BuffManager::loadBuffCSV()
{
	if(m_mapBuffCSV.size() != 0)
		return;
	std::string path = singleton<GameServer>::instance().GetServerPath();
	std::string filename = path + "csv/buff.csv";
#ifndef _WIN32
	filename = "./csv/buff.csv";
#endif
	m_csvReader.Load(filename);

	for (Int32 i = 0; i < m_csvReader.GetRowCount(); i++)
	{
		Int32 id = m_csvReader.GetInt(i,"id");
		if(m_mapBuffCSV.find(id) != m_mapBuffCSV.end())
		{
			LOGGER_ERROR("m_mapBuffCSV.find(id) != m_mapBuffCSV.end(),id:%d",id);
			return;
		}
		m_mapBuffCSV[id].id = id;
		BuffCSVInfo& info = m_mapBuffCSV[id];

		info.type = m_csvReader.GetInt(i,"type");
		info.name = m_csvReader.GetString(i,"name");
		info.description = m_csvReader.GetString(i,"description");
		info.icon_id = m_csvReader.GetInt(i,"icon_id");
	}
}
BuffCSVInfo* BuffManager::GetBuffCSVInfo(Int32 csv_id)
{
	std::map<Int32,BuffCSVInfo>::iterator iter = m_mapBuffCSV.find(csv_id);
	if (iter == m_mapBuffCSV.end())
	{
		LOGGER_ERROR("BuffManager,iter == m_mapBuffCSV.end(),csv_id:%d",csv_id);
		return NULL;
	}
	return &(iter->second);
}